<script type="text/javascript">
    $(document).ready(function () {

        $('form').submit(function (e) {
            e.preventDefault();
            var data = '&email=' + $(this).find('.email').val() +
                    '&word=' + $(this).find('.word').val();

            $.ajax({
                url:'<?php echo base_url() . "forgottenPassword/sendEmail/"?>',
                type:'POST',
                data:data,
                success:function (data) {
                    obj = eval("(" + data + ")");
                    console.log(obj);
                    if (obj == "correct_captcha") {
                        $('.reg_div h1').html('Na email Vám bolo zaslané nové heslo!');
                        $('.forma').empty();
                        $(function () {
                            setTimeout(function () {
                                $('#facebox').hide();
                                $('.warn_comments').hide();
                                $('.warn_thumbs').hide();
                                $('.facebox_overlayBG').hide();
                                $('.facebox_overlay').hide();
                            }, 2000);
                        });
                    }
                    else if (obj == "wrong_captcha") {
                        $('.email_error').html('');
                        $('.captcha_error').html('<span style="font-size:10px; color:red;">Wrong captcha!</span>');
                    }
                    else if (obj == "invalid_email") {
                        $('.captcha_error').html('');
                        $('.email_error').html('<span style="font-size:10px; color:red;">Invalid email!</span>');
                    }

                    // else {
                    //   $('.reg_error').html("");
                    //   if (obj['new_email'] == ""){
                    // 		$('.email_error').html('');
                    // }
                    // if (obj['new_email2']==""){
                    // 	$('.email_error2').html('');
                    // }
                    // 	if (obj['new_email'] != ""){
                    // 		$('.email_error').html('<span style="font-size:10px; color:red;">' + obj['new_email'] + '</span>');
                    // }
                    // if (obj['new_email2']!=""){
                    // 	$('.email_error2').html('<span style="font-size:10px; color:red;">' + obj['new_email2'] + '</span>');
                    // }
                    // }
                }
            });
        });
        $('img').click(function () {
            $.ajax({
                url:'<?php echo base_url() . "forgottenPassword/view"?>',
                type:'POST',
                success:function (data) {
                    obj = eval("(" + data + ")");
                    console.log(obj['image']);
                    //console.log(obj['image']['path']);
                    $('.captcha_img').html(obj['image']);
                }
            });
        });

    });
</script>




<div class="reg_div">
    <h1 style='text-align: center;'>Obnovenie hesla</h1>
    <ul style="list-style: none;text-align: center;padding:3px;" class='forma'>
        <?php echo form_open('forgottenPassword');
        ?>
        <li class="reg_error">
        </li>
        <li>
            <?php echo form_input(array('type' => 'text', 'name' => 'email', 'class' => 'email', 'placeholder' => 'E-mail', 'autocomplete' => 'off')); ?>
        </li>
        <li class="email_error">

        </li>
        <li class="captcha">
			<span class="captcha_img">
			<?php $this->load->view('captcha.php')?>
		</span>
            <img src=<?=base_url() . "css/images/refresh.png"?> alt="refresh button">
        </li>
        <li class="captcha_error">

        </li>
        <li>
            <?php echo form_input(array('type' => 'text', 'name' => 'word', 'class' => 'word', 'placeholder' => 'Captcha word', 'autocomplete' => 'off')); ?>
        </li>
        <li>
            <?php echo form_submit(array('type' => 'submit', 'value' => 'Pošli nové heslo!', 'class' => 'reg_button')); ?>
        </li>
        <?php echo form_close(); ?>

    </ul>

</div>
